'''
附件 treasure.txt 文件里面有许多以元音字母开头(aieuo)且以 ly 或 able 或 ful 结
束的单词。首先写出描述该模式的正则表达式，统计这些单词(大写和小写格式
都认为是同一个单词)在文件里面出现的次数。最后输出这些单词(同样大小写无
关)的出现的次数，在输出时按照单词出现的次数的顺序从大到小排列。
'''
import re
with open('treasure.txt') as f:
    lines = f.readlines()
    results = []
    regex_able = re.compile('\\b[aeiou]\S*able\\b', re.I)
    regex_ly = re.compile('\\b[aeiou]\S*ly\\b', re.I)
    regex_ful = re.compile('\\b[aeiou]\S*ful\\b', re.I)
    for line in lines:
        result_able = regex_able.findall(line)
        result_ly = regex_ly.findall(line)
        result_ful = regex_ful.findall(line)
        results_regex = result_able + result_ly + result_ful
        for result_regex in results_regex:
            results.append(result_regex.lower())
    count_dict = {}
    for result in results:
        count_dict[result] = count_dict.get(result, 0) + 1
    count_dict = sorted(count_dict.items(), key=lambda x: (x[1], x[0]), reverse=True)
    print(count_dict)
    i = 1
    for count in count_dict:
        print(str(i)+"."+count[0]+"  "+str(count[1]))
        i = i+1